package com.hg.design.creation.builder.mine;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class TeamBuilder {
    private List<Staff> staffList;
    private TeamA teamA;
    private TeamB teamB;
    private TeamC teamC;

    public List<Staff> getStaffList() {
        return staffList;
    }

    public void setStaffList(List<Staff> staffList) {
        this.staffList = staffList;
    }

    public TeamA getTeamA() {
        return teamA;
    }

    public TeamB getTeamB() {
        return teamB;
    }

    public TeamC getTeamC() {
        return teamC;
    }

    public TeamBuilder(List<Staff> staffList) {
        this.staffList = staffList;
    }

    public void group() {
        if (this.staffList == null || this.staffList.size() < 18) {
            System.out.println("人数不够");
        }

        Random random = new Random();
        int n = random.nextInt(this.staffList.size());
        Staff teamLeaderA = this.staffList.get(n);
        this.staffList.remove(n);
        n = random.nextInt(this.staffList.size());
        Staff teamLeaderB = this.staffList.get(n);
        this.staffList.remove(n);
        n = random.nextInt(this.staffList.size());
        Staff teamLeaderC = this.staffList.get(n);
        this.staffList.remove(n);
        List<Staff> teamAList = new ArrayList<>();
        List<Staff> teamBList = new ArrayList<>();
        List<Staff> teamCList = new ArrayList<>();
        while (this.staffList.size() > 0) {
            n = random.nextInt(this.staffList.size());
            teamAList.add(this.staffList.get(n));
            this.staffList.remove(n);
            if (this.staffList.size() > 0) {
                n = random.nextInt(this.staffList.size());
                teamBList.add(this.staffList.get(n));
                this.staffList.remove(n);
                if (this.staffList.size() > 0) {
                    n = random.nextInt(this.staffList.size());
                    teamCList.add(this.staffList.get(n));
                    this.staffList.remove(n);
                }
            }
        }

        this.teamA = new TeamA(teamLeaderA, teamAList);
        this.teamB = new TeamB(teamLeaderB, teamBList);
        this.teamC = new TeamC(teamLeaderC, teamCList);
    }
}
